/* Extensive API documentation is at https://github.com/ropg/ezTime */

#include <WiFiUdp.h>
#ifndef _EZTIME_H_
#define _EZTIME_H_

#ifdef __cplusplus
//#if !defined(__time_t_defined) // avoid conflict with newlib or other posix libc
//	typedef unsigned long time_t;
//#endif

#include <inttypes.h>
#include <sys/types.h> // for __time_t_defined, but avr libc lacks sys/types.h

typedef struct  { 
	uint8_t Second; 
	uint8_t Minute; 
	uint8_t Hour; 
	uint8_t Wday;   // day of week, sunday is day 1
	uint8_t Day;
	uint8_t Month; 
	uint8_t Year;   // offset from 1970; 
} tmElements_t;


class Timezone {
	
	public:
	
	uint64_t started;
	uint64_t measured_at;

	time_t _last_sync_time = 0;
	//uint32_t _last_sync_millis = 0;
	uint64_t _last_sync_micros = 0;

	Timezone();	

	time_t tzTime(time_t t);
	
	void breakTime(tmElements_t &tm);
	
	time_t nowUTC();

	void setTime1(time_t t);
	void req(const String server, WiFiUDP* udp);
	bool isRes(WiFiUDP* udp);
	bool res(WiFiUDP* udp, time_t &t);

};


#endif // __cplusplus
#endif //_EZTIME_H_
